<?php
/**
 * Web User
 * @author Alexey Kovalyov akovalyov@piogroup.net
 *
 */
class WebUser extends CWebUser {
	private $_model = null;
	
	const ROLE_ADMIN = 'admin';
	const ROLE_USER = 'user';
	const ROLE_ONCONFIRM = 'on_confirm';

	public function init()
	{
		parent::init();
	}
	
	/**
	 * get user role
	 * @return role
	 */
	public function getRole() {
		$user = $this->getModel();
		return $user->role;
	}

	/**
	 * get user model
	 * @return model
	 */
	public function getModel(){
		if($this->_model)
			return $this->_model;
			
		$this->_model = User::model()->findByPk($this->id);
		
		if(!$this->_model)
			throw new CHttpException(403,'The requested user does not exist.');
			
		return $this->_model; 
	}

	/**
	 * get user full name
	 * @return string
	 */
	public function getName()
	{
		if($this->id)
			return $this->getModel()->first_name .' '. $this->getModel()->last_name;
		else
			return Yii::t('webuser', 'Аноним');
	}

}
?>